<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>欢迎<span></span>登入！</div>
    <div>
        <a href="javascript:;" class="logout">退出登录</a>
    </div>
</body>

</html>
<script src="./js/jquery-3.6.1.min.js"></script>
<script>
    $(function () {
        $.ajax({
            type: 'get',
            url: '/api/index',
            success: (res) => {
                if (res.status == 1) {
                    window.location.href = "/login.html";
                } else {
                    console.log(res);
                    $('span').text(res.resu.user)
                }
            }
        });
        $('.logout').on('click', function () {
            $.ajax({
                type: 'post',
                url: '/api/logout',
                success: (res) => {
                    if (res.status == 0) {
                        window.location.href = "/login.html";
                    } else {
                        alert('服务器异常!');
                    }
                }
            });
        })
    })
</script>